//
//  BCHttpRequestModel.h
//  BCBaseNetworking
//
//  Created by Basic on 15/3/2.
//  网络请求模型

#import <Foundation/Foundation.h>
#import "BCBaseRequestDefines.h"
#import "BCHttpFileModel.h"

@protocol AFMultipartFormData;
NS_ASSUME_NONNULL_BEGIN

@interface BCHttpRequestModel: NSObject
#pragma mark - 属性
/// 唯一值 tag,可用于取消
@property (nonatomic, strong, nullable) id  pacTag;
/// 具体要实现 的delegate
@property (nonatomic, weak, nullable) id  targetDelegate;
/// 禁用使用缓存，默认NO
@property (assign, nonatomic) BOOL  disableCache;
/// 请求的url，需要赋值
@property (nonatomic, strong, nullable) NSString    *requestURL;
/// 请求的host，可以不赋值
@property (nonatomic, strong, nullable) NSString    *requestHost;
/// 请求的Path，可以不赋值
@property (nonatomic, strong, nullable) NSString    *requestPath;
/// 自定义的请求header参数
@property (nonatomic, strong, nullable) NSDictionary<NSString *, id>   *customHeaders;
/// 请求的 cookies 参数
@property (nonatomic, strong) NSMutableDictionary<NSString *, id>   *cookieParams;
/// 请求的 表单参数，包含本地参数和传给server的
@property (nonatomic, strong, nullable) NSDictionary<NSString *, id>   *customPost;
/// 请求的 表单参数,传给server的
@property (nonatomic, strong) NSMutableDictionary<NSString *, id>   *serverPostParams;
/// 请求的 header参数
@property (nonatomic, strong) NSMutableDictionary<NSString *, id>   *headerParams;
/// 最终请求的url,包含get参数
@property (nonatomic, strong) NSString  *finalURL;
/// 最终请求的http body
@property (nonatomic, strong, nullable) id httpBody;
/// 需要上传的文件
@property (nonatomic, strong, nullable) NSArray<BCHttpFileModel *> *files;
/// 请求重拾尝试次数
@property (nonatomic, assign) NSInteger retryCountOnError;
/// 当前请求重拾尝试次数
@property (nonatomic, assign) NSInteger retryCount;
/// 请求超时时间
@property (nonatomic, assign) NSTimeInterval    timeoutInterval;
/// 是否添的cookies，默认 YES
@property (nonatomic, assign) BOOL  addUserCookies;
/// 是否需要添加请求体中的token和doctorId 默认YES
@property (nonatomic, assign) BOOL needUserAuth;
/// 请求的method类型
@property (nonatomic, assign) BCBaseRequestMethod   requestMethod;
/// 请求所属队列的类型
@property (nonatomic, assign) BCRequestQueueType    queueType;
/// 请求内容类型
@property (nonatomic, assign) BCRequestContentType    contentType;
/// 是否用于加载更多
@property (nonatomic, assign) BOOL  isLoadingMore;
/// body构造block
@property (nonatomic, copy, nullable) void (^constructingBodyBlock)(id <AFMultipartFormData> formData);
/// 成功action
@property (nonatomic, copy, nullable) void(^ actionRequestSuccess)(BCBaseRequestOperation *request, BCHttpResponseModel *response);
/// 失败action
@property (nonatomic, copy, nullable) void(^ actionRequestError)(BCBaseRequestOperation *request, BCHttpResponseModel *response);
/// 完成回调action
@property (nonatomic, copy, nullable) void(^bcComplateBlock)(BCHttpRequestModel *request, BCHttpResponseModel *response);

#pragma mark - 公共方法
/**
 *  @brief  构造 BaseRequestModel
 *
 *  @param domain domain
 *  @param param 参数集合
 *  @param method 请求类型
 *  @param successAction 成功action
 *  @param errorAction 失败cation
 *  @param target 请求所属target
 *  @return BCBaseRequest
 */
- (instancetype) initRequestWithDomain:(NSString *_Nullable)domain withParam:(NSDictionary<NSString*, id> *_Nullable)param withMethod:(BCBaseRequestMethod)method withSuccess:(void(^_Nullable)(BCBaseRequestOperation *request, BCHttpResponseModel *response) )successAction withError:(void(^_Nullable)(BCBaseRequestOperation *request, BCHttpResponseModel *response) )errorAction withTarget:(id)target;



#pragma mark - response 回调处理
/**
 *  请求成功回调，子类可以重写
 *
 *  @param request  请求operation
 *  @param response 返回数据对象
 */
-(void)onReponseSuccessAction:(BCBaseRequestOperation *)request withResponse:(BCHttpResponseModel *)response;

/**
 *  请求失败回调，子类可以重写
 *
 *  @param request  请求operation
 *  @param response 返回数据对象
 */
-(void)onReponseErrorAction:(BCBaseRequestOperation *)request withResponse:(BCHttpResponseModel *)response;
@end


NS_ASSUME_NONNULL_END
